Imports Col = System.Collections
Imports Com = System.Runtime.CompilerServices
Imports Dia = System.Diagnostics
Imports Gen = System.Collections.Generic
Imports Ref = System.Reflection
Imports Sys = System

Namespace Enhancements.Core.Logging
    ''' <summary>Management-type class used as the central access point for the logging framework.</summary>
    <Serializable()> _
    Public NotInheritable Class Logs

        Private Shared __LogCollection As Gen.List(Of Log) = New Gen.List(Of Log)

        ''' <summary>Event raised whenever an exception occurs inside the logging framework, and which is not intended for normal propagation.</summary>
        Public Shared Event ExceptionOccurred As ExceptionOccurredEventHandler
        Friend Shared Sub ___OnExceptionOccurred(ByVal _exception As Sys.Exception)
            RaiseEvent ExceptionOccurred(Nothing, New ExceptionOccurredEventArgs(_exception))
        End Sub

        Private Sub New()
        End Sub

        ''' <summary>Loads the logging framework's configuration from the specified file, and puts it to use immediately.</summary>
        ''' <param name="_path">Path of the file that contains the configuration to use.</param>
        ''' <exception cref="IsNullException">_path is null.</exception>
        ''' <exception cref="IsPathValidNotException">_path contains at least one invalid character.</exception>
        ''' <exception cref="IsFileExistentNotException">No file exists at the specified path.</exception>
        Public Shared Sub Load(ByVal _path As System.String)
            ___Assert.___IsFileExistent("_path", _path, True)

            Dim _collectionClientRun As Gen.List(Of Log) = ___ConfigurationFile.___LoadClientRun(_path)
            For Each _collectionItem As Log In __LogCollection
                _collectionItem.___Dispose()
            Next _collectionItem
            __LogCollection = _collectionClientRun
        End Sub

        Private Shared __InitializeCalled As System.Boolean = False
        ''' <summary>Indicates if the logging framework was already initialized.</summary>
        Public Shared ReadOnly Property InitializeCalled() As System.Boolean
            Get
                Return __InitializeCalled
            End Get
        End Property

        ''' <summary>Initializes the logging framework making it usable.</summary>
        ''' <exception cref="IsInitializedException">Logs was already initialized.</exception>
        ''' <exception cref="IsDisposedNotException">Logs was already disposed.</exception>
        Public Shared Sub Initialize()
            ___Assert.___IsInitializedNot("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
            __InitializeCalled = True

            ___ConfigurationFile.___Initialize()

            Dim _collectionServerBuild As Gen.List(Of Log) = ___ConfigurationFile.___LoadServerBuild()
            __LogCollection = _collectionServerBuild

            Dim _collectionClientLaunch As Gen.List(Of Log) = ___ConfigurationFile.___LoadClientLaunch()
            If ___Assert.___IsNullNot("_collectionClientLaunch", _collectionClientLaunch, False) Then
                For Each _collectionItem As Log In __LogCollection
                    _collectionItem.___Dispose()
                Next _collectionItem
                __LogCollection = _collectionClientLaunch
            End If
        End Sub

        Private Shared __DisposeCalled As System.Boolean = False
        ''' <summary>Indicates if the logging framework was already disposed.</summary>
        Public Shared ReadOnly Property DisposeCalled() As System.Boolean
            Get
                Return __DisposeCalled
            End Get
        End Property

        ''' <summary>Disposes the logging framework making it unusable.</summary>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        Public Shared Sub Dispose()
            ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
            __DisposeCalled = True

            For Each _collectionLog As Log In __LogCollection
                _collectionLog.___Dispose()
            Next _collectionLog
            __LogCollection.Clear()
        End Sub

        ''' <summary>Adds a log processor to the logging framework.</summary>
        ''' <param name="_log">Log processor.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_log is null.</exception>
        ''' <exception cref="IsTrueException">_log was already added.</exception>
        Public Shared Sub Add(ByVal _log As Log)
            ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
            ___Assert.___IsNullNot("_log", _log, True)
            ___Assert.___IsTrueNot("__Collection.Contains(_log)", __LogCollection.Contains(_log), True)

            __LogCollection.Add(_log)
        End Sub

        ''' <summary>Clears the Log instances list.</summary>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        Public Shared Sub Clear()
            ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)

            __LogCollection.Clear()
        End Sub

        ''' <summary>Removes a previously added log processor from the logging framework.</summary>
        ''' <param name="_log">Log processor.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsTrueException">_log was not added.</exception>
        Public Shared Sub Remove(ByVal _log As Log)
            ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
            ___Assert.___IsTrue("__Collection.Contains(_log)", __LogCollection.Contains(_log), True)

            __LogCollection.Remove(_log)
        End Sub

        ''' <summary>Removes a previously added log processor from the logging framework.</summary>
        ''' <param name="_index">Index of the Log processor.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsInRangeNotException">_index is invalid according to the Log instances previously added.</exception>
        Public Shared Sub RemoveAt(ByVal _index As Sys.Int32)
            ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
            ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
            ___Assert.___IsInRange("__Collection.Count", __LogCollection.Count, 1, Sys.Int32.MaxValue, True)
            ___Assert.___IsInRange("_index", _index, 0, __LogCollection.Count - 1, True)

            __LogCollection.RemoveAt(_index)
        End Sub

        ''' <summary>Returns one of the Log instances already added.</summary>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsInRangeNotException">_index is invalid according to the Log instances previously added.</exception>
        Public Shared ReadOnly Property Item(ByVal _index As Sys.Int32) As Log
            Get
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsInRange("__Collection.Count", __LogCollection.Count, 1, Sys.Int32.MaxValue, True)
                ___Assert.___IsInRange("_index", _index, 0, __LogCollection.Count - 1, True)

                Return __LogCollection(_index)
            End Get
        End Property

        ''' <summary>Returns the amount of Log instances already added.</summary>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        Public Shared ReadOnly Property Count() As Sys.Int32
            Get
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)

                Return __LogCollection.Count
            End Get
        End Property

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_level">Level of the message.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub Write(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _level As Level, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, _level, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_level">Level of the message.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _level As Level, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, _level, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteError(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Error, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteErrorShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Error, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteWarning(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Warning, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteWarningShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Warning, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteNormal(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Normal, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteNormalShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Normal, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFine(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Fine, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFineShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Fine, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFiner(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Finer, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFinerShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Finer, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_callingObject">Object that calls this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null, or _callingObject is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFinest(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)
                ___Assert.___IsNullNot("_callingObject", _callingObject, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Finest, _callingObject, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        ''' <summary>Adds a message to be wrote by the logging framework.</summary>
        ''' <param name="_procedure">Procedure being executed.</param>
        ''' <param name="_procedureExecutionMoment">Present moment in the life of the procedure that called this routine.</param>
        ''' <param name="_objects">Data to be added to the message.</param>
        ''' <exception cref="IsInitializedNotException">Logs is not initialized.</exception>
        ''' <exception cref="IsDisposedException">Logs was already disposed.</exception>
        ''' <exception cref="IsNullException">_procedure is null.</exception>
        <Com.MethodImpl(Com.MethodImplOptions.Synchronized)> _
        Public Shared Sub WriteFinestShared(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal ParamArray _objects() As Sys.Object)
            Try
                ___Assert.___IsInitialized("Logs[type]", InitializeCalled, True)
                ___Assert.___IsDisposedNot("Logs[type]", DisposeCalled, True)
                ___Assert.___IsNullNot("_procedure", _procedure, True)

                __RecordCreateAndLog(_procedure, _procedureExecutionMoment, Level.Finest, Nothing, _objects)

            Catch _exception As Exception
                ___OnExceptionOccurred(_exception)
            End Try
        End Sub

        Private Shared Sub __RecordCreateAndLog(ByVal _procedure As Ref.MethodBase, ByVal _procedureExecutionMoment As ProcedureExecutionMoment, ByVal _level As Level, ByVal _callingObject As Sys.Object, ByVal ParamArray _objects() As Sys.Object)
            Dim _returnValueUnformattedObjectsList As Gen.List(Of Sys.Object) = New Gen.List(Of Sys.Object)
            If ___Assert.___IsNullNot("_objects", _objects, False) Then
                For Each _objectsObject As Sys.Object In _objects
                    _returnValueUnformattedObjectsList.Add(_objectsObject)
                Next _objectsObject
            End If

            Dim _record As ___Record = New ___Record(Sys.DateTime.Now, Sys.Guid.NewGuid(), _callingObject, _procedure, _level, _procedureExecutionMoment, _returnValueUnformattedObjectsList.ToArray())
            For Each _log As Log In __LogCollection
                _log.___Write(_record)
            Next _log
        End Sub

    End Class
End Namespace
